package org.pz.camunda.controller;

import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.engine.FormService;
import org.camunda.bpm.engine.HistoryService;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.history.HistoricActivityInstance;
import org.camunda.bpm.engine.history.HistoricProcessInstance;
import org.camunda.bpm.engine.runtime.ActivityInstance;
import org.camunda.bpm.engine.task.Task;
import org.pz.camunda.common.StringPoolUtil;
import org.pz.camunda.service.DeployService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 流程实例相关接口
 * */
@CrossOrigin
@RestController
@Slf4j
public class ProcessInstanceController {

    @Autowired
    private RuntimeService runtimeService;

    /**
     * 启动流程，启动一个流程实例
     * @param processDefinitionKey 流程定义 key
     * */
    @RequestMapping("/start/{processDefinitionKey}")
    public void startProcessInstance( @PathVariable("processDefinitionKey") String processDefinitionKey,@RequestBody Map<String, Object> variables) {
        log.info("{} 流程发起，携带参数：{}", processDefinitionKey, variables);

        /*
         * todo 流程发起，这里设置发起人，理论上讲，应该从 request 中获取请求人员，这里直接写死
         */
        variables.put(StringPoolUtil.STARTER, "admin");
        runtimeService.startProcessInstanceByKey(processDefinitionKey, variables);

        /*
         * todo 这里理论上要存下数据库，其他的逻辑处理
         * */
    }


}
